#!/bin/bash
#/etc/keepalived/notify_action.sh
log_file=/var/log/keepalived.log
log_write() {
    echo "[$(date '+%Y-%m-%d %T')] $1" >>$log_file
}
[ ! -d /var/keepalived/ ] && mkdir -p /var/keepalived/

case "$1" in
"MASTER")
    echo -n "$1" >/var/keepalived/state
    log_write " 当前为主节点。"
    echo -n "0" /var/keepalived/vip_check_failed_count
    ;;
"BACKUP")
    echo -n "$1" >/var/keepalived/state
    log_write " 当前为备节点。"
    ;;
"FAULT")
    echo -n "$1" >/var/keepalived/state
    log_write " 节点发生错误。"
    ;;
"STOP")
    echo -n "$1" >/var/keepalived/state
    log_write " 节点已停止运行。"
    ;;
*)
    log_write "notify_action.sh: 运行错误!!!"
    ;;
esac
